package com.ruoyi.web.controller.custom;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.RnxSmsSendLog;
import com.ruoyi.system.service.IRnxSmsSendLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 短信下发记录Controller
 * 
 * @author ruoyi
 * @date 2022-05-12
 */
@Controller
@RequestMapping("/system/smslog")
public class RnxSmsSendLogController extends BaseController
{
    private String prefix = "rnx/smslog";

    @Autowired
    private IRnxSmsSendLogService rnxSmsSendLogService;

    @RequiresPermissions("system:smslog:view")
    @GetMapping()
    public String smslog()
    {
        return prefix + "/smslog";
    }

    /**
     * 查询短信下发记录列表
     */
    @RequiresPermissions("system:smslog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RnxSmsSendLog rnxSmsSendLog)
    {
        startPage();
        List<RnxSmsSendLog> list = rnxSmsSendLogService.selectRnxSmsSendLogList(rnxSmsSendLog);
        return getDataTable(list);
    }

    /**
     * 导出短信下发记录列表
     */
    @RequiresPermissions("system:smslog:export")
    @Log(title = "短信下发记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RnxSmsSendLog rnxSmsSendLog)
    {
        List<RnxSmsSendLog> list = rnxSmsSendLogService.selectRnxSmsSendLogList(rnxSmsSendLog);
        ExcelUtil<RnxSmsSendLog> util = new ExcelUtil<RnxSmsSendLog>(RnxSmsSendLog.class);
        return util.exportExcel(list, "短信下发记录数据");
    }

    /**
     * 新增短信下发记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信下发记录
     */
    @RequiresPermissions("system:smslog:add")
    @Log(title = "短信下发记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RnxSmsSendLog rnxSmsSendLog)
    {
        return toAjax(rnxSmsSendLogService.insertRnxSmsSendLog(rnxSmsSendLog));
    }

    /**
     * 修改短信下发记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RnxSmsSendLog rnxSmsSendLog = rnxSmsSendLogService.selectRnxSmsSendLogById(id);
        mmap.put("rnxSmsSendLog", rnxSmsSendLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信下发记录
     */
    @RequiresPermissions("system:smslog:edit")
    @Log(title = "短信下发记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RnxSmsSendLog rnxSmsSendLog)
    {
        return toAjax(rnxSmsSendLogService.updateRnxSmsSendLog(rnxSmsSendLog));
    }

    /**
     * 删除短信下发记录
     */
    @RequiresPermissions("system:smslog:remove")
    @Log(title = "短信下发记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rnxSmsSendLogService.deleteRnxSmsSendLogByIds(ids));
    }
}
